import MySQLdb
from MySQLdb.cursors import DictCursor

conn = MySQLdb.connect(host='47.107.87.249', port=3306, user='cxk', password='123456',
                       db='hrs', charset='utf8')

try:
    with conn.cursor(DictCursor) as cursor:
        cursor.execute('select dno as 部门编号 ,dname 名称,dloc 办公地点 from tb_dept')
        cxk = cursor.fetchall()
        for c in cxk:
            print(c)
finally:
    conn.close()
